package com.yst.webplugin.api;


import com.yst.web.common.Result;
import com.yst.webplugin.annotation.Default;

import java.lang.annotation.*;

/**
 * API
 */
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Api {

    enum MethodType{
        POST,
        GET;
    }

    enum PostDataType{
        JSON,
        FORM,
    }
    /**
     * name of api
     */
    String value();

    /**
     * Wrapper class for result
     */
    Class<?> resultWrapperClass() default Result.class;

    /**
     * annotation for method api document
     */
    @Target({ElementType.FIELD,ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @interface ApiMethod{
        /**
         * method name
         */
        String value() default "";

        /**
         * type of request method
         */
        MethodType[] methodType() default {};

        /**
         * type of the submit data
         * @return
         */
        PostDataType postDataType() default PostDataType.JSON;

        /**
         * param class
         * @return
         */
        Class<?> paramClass() default Default.class;

        /**
         * version since
         */
        String versionSince() default "1.0.0.0";

        /**
         * indicator for group of require class
         */
        Class<?> requireGroupClass() default Default.class;

        /**
         * indicator to be record log
         */
        boolean recordLog() default true;
    }

    /**
     * api annotation for entity
     */
    @Target({ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @interface ApiEntity{
        String value() default "";
    }

    /**
     * api annotation for field
     */
    @Target({ElementType.FIELD})
    @Retention(RetentionPolicy.RUNTIME)
    @interface ApiField{
        /**
         * description for field
         */
        String value() default "";

        /**
         * example for field
         */
        String valueExample() default "";

        /**
         * specific entity class for map
         */
        Class<?> mapLinkEntity() default Object.class;

        /**
         * indicator of necessary value
         */
        Class<?>[] requireGroupClass() default {};
    }
}
